package com.hyyt.shopjsp.home.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hyyt.shopjsp.basic.pojo.BasicUsers;
import com.hyyt.shopjsp.basic.service.IBasicActorPurviewService;
import com.hyyt.shopjsp.common.controller.BaseController;
import com.hyyt.shopjsp.home.pojo.ShopHomeDayRecommendLbt;
import com.hyyt.shopjsp.home.service.IShopHomeDayRecommendLbtService;
import com.hyyt.shopjsp.util.common.Page;
import com.hyyt.shopjsp.util.common.ResultMsg;
import com.hyyt.shopjsp.util.common.Utils;
import com.hyyt.shopjsp.util.json.FastJsonUtils;

/**
 * Copyright (c) 2016 ShopJsp. All Rights Reserved.
 * ============================================================================
 * 版权所有 2011 - 今 北京华宇盈通科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOPJSP商业授权之前，您不能将本软件应用于商业用途，否则SHOPJSP将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopjsp.com
 * ============================================================================
 * @author Wang Youchun on 2017/03/24 0019下午 1:26.
 */
@Controller
@RequestMapping("/back/dayRecommend")
public class ShopHomeDayrecommendLbtController extends BaseController {
    private Logger logger = Logger.getLogger(ShopHomeDayrecommendLbtController.class);
    private String basePath = "/back/shop/dayRecommend/";
    @Resource
    private IShopHomeDayRecommendLbtService shopHomeDayRecommendLbtService;//首页每日推荐轮播图service

    /**
	 * 进入首页每日推荐轮播图管理
	 *
	 * @return 进入指定页面
	 */
	@RequestMapping("gotoDayRecommendLBTPage")
	public String gotoDayRecommendLBTPage(){
		return basePath+"listDayRecommendLBT";
	}

	/**
	 * 查询所有首页每日推荐轮播图
	 * @param page
	 * @param response
	 */
	@RequestMapping(value="listDayRecommendLBT",method=RequestMethod.POST)
	@ResponseBody
	public void listDayRecommendLBT(String title, String isShow,Page page, HttpServletResponse response){
		Map<String, Object> param = new HashMap<>();
		if (Utils.objectIsNotEmpty(title)){//主题
			param.put("title",title.trim());
		}
		if (Utils.objectIsNotEmpty(isShow)){//显示状态
			param.put("isShow",isShow);
		}
		param.put("sortColumns", "broadcastingId desc");
		int totalRecordCount =shopHomeDayRecommendLbtService.countShopHomeDayRecommendLbt(param);
		page.setPageInfo(page.getPageSize(), totalRecordCount, page.getCurrentPage());
		List<ShopHomeDayRecommendLbt> list =shopHomeDayRecommendLbtService.queryShopHomeDayRecommendLbt(param, page.getPageRecordBeginIndex(), page.getPageSize());
		param.clear();
		param.put("total", totalRecordCount);// total键 存放总记录数，必须的
		param.put("rows", list);// rows键 存放每页记录 list
		ResultMsg.create(param, response);  //把内容发送到页面
	}

	/**
     * 根据首页每日推荐轮播图id获得对象
     *
     * @param broadcastingId
     */
    @RequestMapping(value = "getDayRecommendLBTInfo", method = RequestMethod.POST)
    @ResponseBody
    public ResultMsg getDayRecommendLBTInfo(Integer broadcastingId) {
		if (Utils.objectIsNotEmpty(broadcastingId)) {
			ShopHomeDayRecommendLbt dayRecommendlbt = shopHomeDayRecommendLbtService.loadShopHomeDayRecommendLbt(broadcastingId);
			return ResultMsg.create(true, null, FastJsonUtils.toJSONString(dayRecommendlbt));
		}else {
			return ResultMsg.create(false);
		}
	}

    /**
     * 保存或者修改首页每日推荐轮播图
     *
     * @param shopHomeDayRecommendLbt
     * @return
     */
    @RequestMapping(value = "saveOrUpdateDayRecommendLBT", method = RequestMethod.POST)
    @ResponseBody
	public ResultMsg saveOrUpdateDayRecommendLBT(ShopHomeDayRecommendLbt shopHomeDayRecommendLbt) {
		if (Utils.objectIsNotEmpty(shopHomeDayRecommendLbt)) {
			if (Utils.objectIsEmpty(shopHomeDayRecommendLbt.getBroadcastingId())) {
				shopHomeDayRecommendLbtService.saveShopHomeDayRecommendLbt(shopHomeDayRecommendLbt);
			} else {
				shopHomeDayRecommendLbtService.updateShopHomeDayRecommendLbt(shopHomeDayRecommendLbt);
			}
			return ResultMsg.create(true);
		}else {
			return ResultMsg.create(false);
		}
	}

    /**
     * 根据传入的首页每日推荐轮播图id
     *
     * @param ids
     */
    @RequestMapping(value = "deleteDayRecommendLBT", method = RequestMethod.POST)
    @ResponseBody
	public ResultMsg deleteDayRecommendLBT(String ids) {
		if (Utils.objectIsNotEmpty(ids)) {
			shopHomeDayRecommendLbtService.deleteShopHomeDayRecommendLbt(Integer.parseInt(ids));
			return ResultMsg.create(true);
		}else {
			return ResultMsg.create(false);
		}
	}
}
